package com.yonglian.management.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * A ProjectBaseInfo.
 */
@Entity
@Table(name = "project_base_info")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ProjectBaseInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotNull
    @Size(min = 2, max = 50)
    @Column(name = "project_name", length = 50, nullable = false)
    private String projectName;

    @Column(name = "project_manager")
    private String projectManager;

    @Column(name = "project_location")
    private String projectLocation;

    @Column(name = "amount")
    private Integer amount;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "project")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "properties", "project" }, allowSetters = true)
    private Set<Activity> activities = new HashSet<>();

    @ManyToOne(fetch = FetchType.EAGER)
    @JsonIgnoreProperties(value = { "projects" }, allowSetters = true)
    private ProjectType projectType;

    // jhipster-needle-entity-add-field - JHipster will add fields here

    public Long getId() {
        return this.id;
    }

    public ProjectBaseInfo id(Long id) {
        this.setId(id);
        return this;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getProjectName() {
        return this.projectName;
    }

    public ProjectBaseInfo projectName(String projectName) {
        this.setProjectName(projectName);
        return this;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getProjectManager() {
        return this.projectManager;
    }

    public ProjectBaseInfo projectManager(String projectManager) {
        this.setProjectManager(projectManager);
        return this;
    }

    public void setProjectManager(String projectManager) {
        this.projectManager = projectManager;
    }

    public String getProjectLocation() {
        return this.projectLocation;
    }

    public ProjectBaseInfo projectLocation(String projectLocation) {
        this.setProjectLocation(projectLocation);
        return this;
    }

    public void setProjectLocation(String projectLocation) {
        this.projectLocation = projectLocation;
    }

    public Integer getAmount() {
        return this.amount;
    }

    public ProjectBaseInfo amount(Integer amount) {
        this.setAmount(amount);
        return this;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Set<Activity> getActivities() {
        return this.activities;
    }

    public void setActivities(Set<Activity> activities) {
        if (this.activities != null) {
            this.activities.forEach(i -> i.setProject(null));
        }
        if (activities != null) {
            activities.forEach(i -> i.setProject(this));
        }
        this.activities = activities;
    }

    public ProjectBaseInfo activities(Set<Activity> activities) {
        this.setActivities(activities);
        return this;
    }

    public ProjectBaseInfo addActivity(Activity activity) {
        this.activities.add(activity);
        activity.setProject(this);
        return this;
    }

    public ProjectBaseInfo removeActivity(Activity activity) {
        this.activities.remove(activity);
        activity.setProject(null);
        return this;
    }

    public ProjectType getProjectType() {
        return this.projectType;
    }

    public void setProjectType(ProjectType projectType) {
        this.projectType = projectType;
    }

    public ProjectBaseInfo projectType(ProjectType projectType) {
        this.setProjectType(projectType);
        return this;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ProjectBaseInfo)) {
            return false;
        }
        return getId() != null && getId().equals(((ProjectBaseInfo) o).getId());
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "ProjectBaseInfo{" +
            "id=" + getId() +
            ", projectName='" + getProjectName() + "'" +
            ", projectManager='" + getProjectManager() + "'" +
            ", projectLocation='" + getProjectLocation() + "'" +
            ", amount=" + getAmount() +
            "}";
    }
}
